package com.kazimsoylu;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.kazimsoylu.jdbc.dao.EmployeeDao;
import com.kazimsoylu.jpa.model.Department;
import com.kazimsoylu.jpa.model.Employee;
import com.kazimsoylu.jpa.model.EmployeeInfo;
import com.kazimsoylu.jpa.service.persistence.EntityService;
import com.kazimsoylu.utils.BeanFactory;

public class Main {
	public static void main(String[] args) 
	{		
		EmployeeDao employeeDao = BeanFactory.getInstance().getBean(
				"employeeDao", EmployeeDao.class);

		System.out.println("---getEmployeesQueryForList-----");
		List<Map<String, Object>> employeeList = employeeDao
				.getEmployeesQueryForList();
		for (Map<String, Object> employeeMap : employeeList) {
			System.out.printf("Number: %d, Name:%s %s\n",
					employeeMap.get("employeeNumber"),
					employeeMap.get("firstName"), employeeMap.get("lastName"));
		}

		System.out.println("---getEmployeesRowMapper-----");
		List<Employee> empList = employeeDao.getEmployeesRowMapper();
		for (Employee e : empList) {
			System.out.printf("Number: %d, Name:%s %s\n",
					e.getEmployeeNumber(), e.getFirstName(), e.getLastName());
		}

		System.out.println("---getEmployeesRowMapperV2-----");
		empList = employeeDao.getEmployeesRowMapper();
		for (Employee e : empList) {
			System.out.printf("Number: %d, Name:%s %s\n",
					e.getEmployeeNumber(), e.getFirstName(), e.getLastName());
		}

		System.out.println("---Employee Name----");
		String name = employeeDao.getEmployeeName(1002);
		System.out.println("Name=" + name);

		System.out.println("---Distinct Job Titles----");
		List<String> distinctJobs = employeeDao.getDistinctJobTitles();
		for (String s : distinctJobs)
			System.out.println("Job Name:" + s);

		System.out.println("---Get Employee----");
		Employee employee = employeeDao.getEmployee(1002);
		System.out.println(employee);
		
		System.out.println("---Employee Count---");
		int employeeCount = employeeDao.getEmployeeCount();
		System.out.println("Employee Count:"+employeeCount);
		
		
		EntityService entityService = BeanFactory.getInstance().getBean( "entityService" , EntityService.class);
		Employee e = entityService.getEntity( Employee.class , 1002);
		System.out.println("Employee:"+e);
		
		List<Employee> employees = entityService.getByNamedQuery( "Employee.getAllEmployees" );
		for( Employee emp : employees )
			System.out.println(emp);
		
		
		employees = entityService.getByNamedQuery( "Employee.getByJobTitle","ENGINEER" );
		for( Employee emp : employees )
			System.out.println(emp);
		
		Department dep = entityService.getEntity( Department.class, 1);
		Set<Employee> dep_emp = dep.getEmployees();
		for( Employee em : dep_emp )
			System.out.println(em);
		
		
		System.out.println("---EmployeeInfo---");
		List<EmployeeInfo> empInfoList = entityService.getEntities( EmployeeInfo.class );
		for(EmployeeInfo ei : empInfoList)
			System.out.println(ei);

	}

}
